package com.education.springbootdemo.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class LogAspect {

    //带参数
    @Pointcut("execution(public * com.education.springbootdemo.mail.EmailServiceImpl.sendEmail(String,String,String)) && args())")
    public void sendEmail() {}

    // * 、 。。
    @Pointcut("execution(public * com.education.springbootdemo.service.*.*(..))")
    public  void log(){}

    @Before("sendEmail()")
    public  void sendEmailLog(ProceedingJoinPoint pjp) {
//       System.out.println(to);
//        System.out.println(from);
//        System.out.println(body);
    }

    @Around("log()")
    public Object around(ProceedingJoinPoint pjp) {
        System.out.println("around");
        try {
          Object ret =   pjp.proceed();

          System.out.println("around finish");
          return ret;
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}
